<?php
class background_pc_default_common_action extends wwy_action
{
    protected $_view_dir = PROJECT_ROOT_PATH . '/no_public/module/background/pc/view/view';
    protected $_library_dir = PROJECT_ROOT_PATH . '/no_public/module/background/pc/view/library';
    protected $_layout_dir = PROJECT_ROOT_PATH . '/no_public/module/background/pc/view/layout';

    protected $_layout = 'common/layout.php';

    protected $_if_require_login = true;
        
    public function run()
    {
        $this->_pre_run();
        if(self::$_view_status < 0){
	        return;
	    }
    
        $this->_current_page_run();
    
        $this->_post_run();
    }
    
    protected function _pre_run()
    {
        parent::_pre_run();   
        
        $this->check_login();
    }
    
    protected function check_login()
    {
        if($this->_if_require_login){
            $result = array('status' => 0, 'message' => '', 'data' => array());
            
            if(empty($_SESSION['admin_user_name'])){                               
                $result['status']  = -401;
                $result['message'] = '未登录';
                	
                $this->set_view_status($result['status']);
                $this->set_view_message($result['message']);
                
                $url = $this->get_url(array('route' => 'pc_background_index_login'), true);
                echo '<script type="text/javascript">window.top.location.replace("'. $url . '");</script>';
            }
        }
    }
    
    /**
     * 渲染布局、合成整个页面，并输出
     */
    protected function _render()
    {
        //var_dump(__METHOD__); exit();
        //渲染布局中使用到的库
        self::$_layout_data['library_footer'] = $this->_render_library('common/footer.php');
        
        //页面标题
        $this->_set_page_title();

        $layout_content = $this->_render_layout($this->_layout);
        echo $layout_content;
    }
    
    /**
     * 对应页面必须设置【self::$_view_data['page_title']】，用于生成【self::$_layout_data['page_title']】
     */
    protected function _set_page_title()
    {
        $page_title = self::$_view_data['business_config']['title'] . '_管理后台';
    
        if(!empty(self::$_view_data['page_title'])){
            $page_title = self::$_view_data['page_title'] . ' | ' . $page_title;
        }
    
        self::$_layout_data['page_title'] = $page_title;      
    }
}